//
//  ABServiceStore.m
//  TTProject
//
//  Created by 张志恒 on 16/9/20.
//  Copyright © 2016年 Dail. All rights reserved.
//

#import "ABServiceStore.h"

@interface ABServiceStore ()

@property (nonatomic, strong) NSMutableDictionary *serviceStorage;

@end

@implementation ABServiceStore

#pragma mark - getters and setters
- (NSMutableDictionary *)serviceStorage
{
    if (_serviceStorage == nil) {
        _serviceStorage = [[NSMutableDictionary alloc] init];
    }
    return _serviceStorage;
}

#pragma mark - life cycle
+ (instancetype)sharedInstance
{
    static dispatch_once_t onceToken;
    static ABServiceStore *sharedInstance;
    dispatch_once(&onceToken, ^{
        sharedInstance = [[ABServiceStore alloc] init];
    });
    return sharedInstance;
}

#pragma mark - public methods
- (ABService<ABServiceProtocol> *)serviceWithIdentifier:(NSString *)identifier
{
    return self.serviceStorage[identifier];
}

- (void)addService:(ABService<ABServiceProtocol> *)service withIdentifier:(NSString *)identifier
{
    if (self.serviceStorage[identifier] == nil) {
        self.serviceStorage[identifier] = service;
    }
}

- (void)removeServiceWithIdentifier:(NSString *)identifier
{
    [self.serviceStorage removeObjectForKey:identifier];
}

@end
